<template>
  <div class="course-overview">
    <!-- 课程简介 -->
    <div class="section">
      <h2 class="section-title">课程简介</h2>
      <div class="section-content">
        <div class="paragraph" v-html="courseDetail.courseIntroduce"></div>
      </div>
    </div>

    <!-- 课程目标 -->
    <div class="section">
      <h2 class="section-title">课程目标</h2>
      <div class="section-content">
        <div class="paragraph" v-html="courseDetail.courseTarget">
        </div>
      </div>
    </div>
    <!-- 课程重点难点 -->
    <div class="section">
      <h2 class="section-title">课程重点难点</h2>
      <div class="section-content">
        <div class="paragraph" v-html="courseDetail.courseKeynote" >
        
        </div>
      </div>
    </div>
    <!-- 推荐课外读物 -->
    <div class="section">
      <h2 class="section-title">推荐课外读物</h2>
      <div class="section-content">
        <div class="section-content_item" v-for="(item) in recommendbook" :key="item.crId">
          <img :src="baseURL + item.crFileUrl">
          <div class="bookname">{{ removeFileSuffix(item.crName) }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import courseRelated from '@/api/courseRelated';
export default {
  name: 'CourseOverview',
  props: {
    courseDetail: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      recommendbook: [],
      baseURL: process.env.VUE_APP_BASE_API
    }
  },
  mounted(){
    this.initData();
  },
  watch: {
    courseDetail: {
      handler(newVal) {
        if (newVal) {
          // 这里可以根据实际的数据结构更新组件的显示内容
          this.background = newVal.background || this.background;
          this.introduction = newVal.introduction || this.introduction;
          this.objectives = newVal.objectives || this.objectives;
        }
      },
      immediate: true
    }
  },
  methods:{
    initData(){
      const query = {
        resourceCategory: 'book'
      }
      courseRelated.getCourseResource(query).then((res)=>{
        console.log('课外读物',res);
        if(res && res.rows && Array.isArray(res.rows)) {
          this.recommendbook = res.rows;
        }
      });
    },
    removeFileSuffix(fileName) {
      if(!fileName) return '';
      return fileName.replace(/\.[^/.]+$/, '');
    }
  }
}
</script>

<style lang="scss" scoped>
.course-overview {
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    padding: 20px;
    overflow-y: auto;
  .section {
    margin-bottom: 40px;

    .section-title {
      font-size: 24px;
      font-weight: bold;
      color: #333;
      margin-bottom: 20px;
      position: relative;
      padding-left: 15px;

      &::before {
        content: '';
        position: absolute;
        left: 0;
        top: 50%;
        transform: translateY(-50%);
        width: 4px;
        height: 20px;
        background: #349fe0;
        border-radius: 2px;
      }
    }

    .section-content {
      width: 100%;
      display: flex;
      flex-wrap: wrap;
      gap: 20px;
      
      .section-content_item{
        cursor: pointer;
        width: 280px;
        height: 350px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: space-around;
        background-color: #f7f7f7;
        border-radius: 10px;
        padding: 15px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.05);
        transition: all 0.3s ease;
        
        &:hover {
          transform: translateY(-5px);
          box-shadow: 0 5px 15px rgba(0,0,0,0.1);
        }
        
        img{
          width: 200px;
          height: 240px;
          object-fit: contain;
          margin-bottom: 15px;
        }
        
        .bookname{
          font-size: 16px;
          font-weight: bold;
          text-align: center;
          width: 100%;
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-line-clamp: 2;
          -webkit-box-orient: vertical;
        }
      }
    }
  }
}

// 滚动条样式
::-webkit-scrollbar {
  width: 0px;
}

::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 3px;
}

::-webkit-scrollbar-track {
  background: #f5f5f5;
}
</style>
